using System.Collections.Generic;
using System.IO;
using System.Linq;
using Pronghorn.Core;

namespace ViewEngine_Tests
{
	public class DemoSkin : SkinBase
	{
		public DemoSkin(IProngHornSkinContext skinContext, ICollectionRenderer collectionRenderer, IFileLinkRenderer scriptRenderer, IFileLinkRenderer cssRenderer)
			: base(skinContext, collectionRenderer, scriptRenderer,cssRenderer)
		{
		}

		protected override void GenerateHtml(TextWriter writer)
		{
			writer.Write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
			writer.Write("<html>");
			writer.Write("    <head>");
			writer.Write(string.Format("        <title>{0}</title>", Model.PageTitle));
			RenderCollection(Model.GetMetaTags(), writer);
			RenderCss(writer);
			RenderScripts(writer);
			writer.Write("    </head>");
			writer.Write("    <body>");
			var scenes = Model.Data.GetIEnumerable("scenes");
			if (scenes != null)
			{
			    foreach (var scene in scenes)
			    {
			        writer.Write(string.Format("     <img src=\"{0}\" title=\"{1}\" border=\"0\"/>", Model.Data.GetString("scene.src"), Model.Data.GetString("scene.title")));
			    }
			}
			writer.Write("        <div class=\"className\" onClick=\"alert('my name here');\">");
			writer.Write("            <div>");
			var arealeftnavbar = Model.Areas.FirstOrDefault(a => a.Name.ToLower() == "leftnavbar");
			RenderCollection((IList<IRenderable>) arealeftnavbar.Layout, writer);

			writer.Write("            </div>");
			writer.Write("            <div>");
			var areacontent = Model.Areas.FirstOrDefault(a => a.Name.ToLower() == "content");
			RenderCollection((IList<IRenderable>)areacontent.Layout, writer);

			writer.Write("            </div>");
			writer.Write("            <div>");
			var arearightnavbar = Model.Areas.FirstOrDefault(a => a.Name.ToLower() == "rightnavbar");
			RenderCollection((IList<IRenderable>)arearightnavbar.Layout, writer);

			writer.Write("            </div>");
			writer.Write("        </div>");
			writer.Write("    </body>");
			writer.Write("</html>");
		}
	}
}